/*
 * Copyright 2018 Zhongan.com All right reserved. This software is the
 * confidential and proprietary information of Zhongan.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Zhongan.com.
 */

package com.zhongan.cloud.gateway.filter.previous;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;

/**
 * 兼容原有网关
 *
 * @author tongyufu
 */
//@Configuration
public class PreviousFilter {

    @Autowired
    private PreviousApiFilterFactory      previousApiFilterFactory;
    @Autowired
    private PreviousIntranetFilterFactory previousIntranetFilterFactory;

    @Bean
    public RouteLocator previousRouteLocator(RouteLocatorBuilder builder) {
        return builder
                .routes()
                .route(r -> r
                        .path("/gateway/api")
                        .filters(
                                f -> f.filter(previousApiFilterFactory.apply(previousApiFilterFactory.newConfig()), 10))
                        .uri("http://www.baidu.com"))
                .route(r -> r
                        .path("/gateway/intranet")
                        .filters(
                                f -> f.filter(
                                        previousIntranetFilterFactory.apply(previousIntranetFilterFactory.newConfig()),
                                        11)).uri("http://www.baidu.com")).build();
    }

}
